{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025/8/25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025/8/26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025/8/27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025/8/28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025/8/29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day  Preclose      Open   Highest    Lowest     Close\n",
       "0     1990/12/19              96.050    99.980    95.790    99.980\n",
       "1     1990/12/20     99.98   104.300   104.390    99.980   104.390\n",
       "2     1990/12/21    104.39   109.070   109.130   103.730   109.130\n",
       "3     1990/12/24    109.13   113.570   114.550   109.130   114.550\n",
       "4     1990/12/25    114.55   120.090   120.250   114.550   120.250\n",
       "...          ...       ...       ...       ...       ...       ...\n",
       "8468   2025/8/25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "8469   2025/8/26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8470   2025/8/27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8471   2025/8/28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8472   2025/8/29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=pd.read_csv('D:/Python2025/000001.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选取单列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         99.980\n",
       "1        104.390\n",
       "2        109.130\n",
       "3        114.550\n",
       "4        120.250\n",
       "          ...   \n",
       "8468    3883.562\n",
       "8469    3868.382\n",
       "8470    3800.350\n",
       "8471    3843.597\n",
       "8472    3857.927\n",
       "Name: Close, Length: 8473, dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Close']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选取多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025/8/25</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025/8/26</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025/8/27</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025/8/28</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025/8/29</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day     Close\n",
       "0     1990/12/19    99.980\n",
       "1     1990/12/20   104.390\n",
       "2     1990/12/21   109.130\n",
       "3     1990/12/24   114.550\n",
       "4     1990/12/25   120.250\n",
       "...          ...       ...\n",
       "8468   2025/8/25  3883.562\n",
       "8469   2025/8/26  3868.382\n",
       "8470   2025/8/27  3800.350\n",
       "8471   2025/8/28  3843.597\n",
       "8472   2025/8/29  3857.927\n",
       "\n",
       "[8473 rows x 2 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[['Day','Close']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选取行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td></td>\n",
       "      <td>96.05</td>\n",
       "      <td>99.98</td>\n",
       "      <td>95.79</td>\n",
       "      <td>99.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.30</td>\n",
       "      <td>104.39</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.07</td>\n",
       "      <td>109.13</td>\n",
       "      <td>103.73</td>\n",
       "      <td>109.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.57</td>\n",
       "      <td>114.55</td>\n",
       "      <td>109.13</td>\n",
       "      <td>114.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.09</td>\n",
       "      <td>120.25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1990/12/26</td>\n",
       "      <td>120.25</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>120.25</td>\n",
       "      <td>125.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1990/12/27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.28</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1990/12/28</td>\n",
       "      <td>125.28</td>\n",
       "      <td>126.39</td>\n",
       "      <td>126.45</td>\n",
       "      <td>125.28</td>\n",
       "      <td>126.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1990/12/31</td>\n",
       "      <td>126.45</td>\n",
       "      <td>126.56</td>\n",
       "      <td>127.61</td>\n",
       "      <td>126.48</td>\n",
       "      <td>127.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1991/1/2</td>\n",
       "      <td>127.61</td>\n",
       "      <td>127.61</td>\n",
       "      <td>128.84</td>\n",
       "      <td>127.61</td>\n",
       "      <td>128.84</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Day  Preclose    Open  Highest  Lowest   Close\n",
       "0  1990/12/19             96.05    99.98   95.79   99.98\n",
       "1  1990/12/20     99.98  104.30   104.39   99.98  104.39\n",
       "2  1990/12/21    104.39  109.07   109.13  103.73  109.13\n",
       "3  1990/12/24    109.13  113.57   114.55  109.13  114.55\n",
       "4  1990/12/25    114.55  120.09   120.25  114.55  120.25\n",
       "5  1990/12/26    120.25  125.27   125.27  120.25  125.27\n",
       "6  1990/12/27    125.27  125.27   125.28  125.27  125.28\n",
       "7  1990/12/28    125.28  126.39   126.45  125.28  126.45\n",
       "8  1990/12/31    126.45  126.56   127.61  126.48  127.61\n",
       "9    1991/1/2    127.61  127.61   128.84  127.61  128.84"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2246</th>\n",
       "      <td>1999/12/21</td>\n",
       "      <td>1419.55</td>\n",
       "      <td>1416.5</td>\n",
       "      <td>1416.5</td>\n",
       "      <td>1388.06</td>\n",
       "      <td>1395.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day Preclose    Open  Highest   Lowest   Close\n",
       "2246  1999/12/21  1419.55  1416.5   1416.5  1388.06  1395.5"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['Day']=='1999/12/21']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4092</th>\n",
       "      <td>2007/8/23</td>\n",
       "      <td>4980.07</td>\n",
       "      <td>5002.84</td>\n",
       "      <td>5050.38</td>\n",
       "      <td>4968.33</td>\n",
       "      <td>5032.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4093</th>\n",
       "      <td>2007/8/24</td>\n",
       "      <td>5032.49</td>\n",
       "      <td>5070.65</td>\n",
       "      <td>5125.36</td>\n",
       "      <td>5052.24</td>\n",
       "      <td>5107.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4094</th>\n",
       "      <td>2007/8/27</td>\n",
       "      <td>5107.67</td>\n",
       "      <td>5144.82</td>\n",
       "      <td>5192.06</td>\n",
       "      <td>5092.08</td>\n",
       "      <td>5150.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4095</th>\n",
       "      <td>2007/8/28</td>\n",
       "      <td>5150.12</td>\n",
       "      <td>5134.14</td>\n",
       "      <td>5209.51</td>\n",
       "      <td>5058.45</td>\n",
       "      <td>5194.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4096</th>\n",
       "      <td>2007/8/29</td>\n",
       "      <td>5194.69</td>\n",
       "      <td>5147.71</td>\n",
       "      <td>5204.53</td>\n",
       "      <td>5063.41</td>\n",
       "      <td>5109.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5986</th>\n",
       "      <td>2015/6/10</td>\n",
       "      <td>5113.53</td>\n",
       "      <td>5049.20</td>\n",
       "      <td>5164.16</td>\n",
       "      <td>5001.49</td>\n",
       "      <td>5106.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5987</th>\n",
       "      <td>2015/6/11</td>\n",
       "      <td>5106.04</td>\n",
       "      <td>5101.44</td>\n",
       "      <td>5122.46</td>\n",
       "      <td>5050.77</td>\n",
       "      <td>5121.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5988</th>\n",
       "      <td>2015/6/12</td>\n",
       "      <td>5121.59</td>\n",
       "      <td>5143.34</td>\n",
       "      <td>5178.19</td>\n",
       "      <td>5103.40</td>\n",
       "      <td>5166.35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5989</th>\n",
       "      <td>2015/6/15</td>\n",
       "      <td>5166.35</td>\n",
       "      <td>5174.42</td>\n",
       "      <td>5176.80</td>\n",
       "      <td>5048.74</td>\n",
       "      <td>5062.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5990</th>\n",
       "      <td>2015/6/16</td>\n",
       "      <td>5062.99</td>\n",
       "      <td>5004.41</td>\n",
       "      <td>5029.68</td>\n",
       "      <td>4842.10</td>\n",
       "      <td>4887.43</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>97 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day Preclose     Open  Highest   Lowest    Close\n",
       "4092  2007/8/23  4980.07  5002.84  5050.38  4968.33  5032.49\n",
       "4093  2007/8/24  5032.49  5070.65  5125.36  5052.24  5107.67\n",
       "4094  2007/8/27  5107.67  5144.82  5192.06  5092.08  5150.12\n",
       "4095  2007/8/28  5150.12  5134.14  5209.51  5058.45  5194.69\n",
       "4096  2007/8/29  5194.69  5147.71  5204.53  5063.41  5109.43\n",
       "...         ...      ...      ...      ...      ...      ...\n",
       "5986  2015/6/10  5113.53  5049.20  5164.16  5001.49  5106.04\n",
       "5987  2015/6/11  5106.04  5101.44  5122.46  5050.77  5121.59\n",
       "5988  2015/6/12  5121.59  5143.34  5178.19  5103.40  5166.35\n",
       "5989  2015/6/15  5166.35  5174.42  5176.80  5048.74  5062.99\n",
       "5990  2015/6/16  5062.99  5004.41  5029.68  4842.10  4887.43\n",
       "\n",
       "[97 rows x 6 columns]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['Open']>5000]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990-12-21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990-12-24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990-12-25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025-08-25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025-08-26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025-08-27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025-08-28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025-08-29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day  Preclose      Open   Highest    Lowest     Close\n",
       "0    1990-12-19              96.050    99.980    95.790    99.980\n",
       "1    1990-12-20     99.98   104.300   104.390    99.980   104.390\n",
       "2    1990-12-21    104.39   109.070   109.130   103.730   109.130\n",
       "3    1990-12-24    109.13   113.570   114.550   109.130   114.550\n",
       "4    1990-12-25    114.55   120.090   120.250   114.550   120.250\n",
       "...         ...       ...       ...       ...       ...       ...\n",
       "8468 2025-08-25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "8469 2025-08-26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8470 2025-08-27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8471 2025-08-28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8472 2025-08-29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Day']=pd.to_datetime(data['Day'],format='%Y/%m/%d')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "数据排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4125</th>\n",
       "      <td>2007-10-16</td>\n",
       "      <td>6030.09</td>\n",
       "      <td>6056.95</td>\n",
       "      <td>6124.04</td>\n",
       "      <td>6040.71</td>\n",
       "      <td>6092.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4126</th>\n",
       "      <td>2007-10-17</td>\n",
       "      <td>6092.06</td>\n",
       "      <td>6057.43</td>\n",
       "      <td>6088.89</td>\n",
       "      <td>5982.20</td>\n",
       "      <td>6036.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4124</th>\n",
       "      <td>2007-10-15</td>\n",
       "      <td>5903.26</td>\n",
       "      <td>5934.77</td>\n",
       "      <td>6039.04</td>\n",
       "      <td>5866.13</td>\n",
       "      <td>6030.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4136</th>\n",
       "      <td>2007-10-31</td>\n",
       "      <td>5897.19</td>\n",
       "      <td>5984.71</td>\n",
       "      <td>6002.12</td>\n",
       "      <td>5871.48</td>\n",
       "      <td>5954.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4137</th>\n",
       "      <td>2007-11-01</td>\n",
       "      <td>5954.77</td>\n",
       "      <td>5978.94</td>\n",
       "      <td>6005.13</td>\n",
       "      <td>5912.50</td>\n",
       "      <td>5914.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>1991-05-17</td>\n",
       "      <td>105.77</td>\n",
       "      <td>105.12</td>\n",
       "      <td>106.75</td>\n",
       "      <td>104.96</td>\n",
       "      <td>106.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>1991-05-15</td>\n",
       "      <td>107.19</td>\n",
       "      <td>106.56</td>\n",
       "      <td>106.60</td>\n",
       "      <td>106.42</td>\n",
       "      <td>106.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>102</th>\n",
       "      <td>1991-05-16</td>\n",
       "      <td>106.57</td>\n",
       "      <td>105.83</td>\n",
       "      <td>105.86</td>\n",
       "      <td>105.69</td>\n",
       "      <td>105.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.30</td>\n",
       "      <td>104.39</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.05</td>\n",
       "      <td>99.98</td>\n",
       "      <td>95.79</td>\n",
       "      <td>99.98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day  Preclose     Open  Highest   Lowest    Close\n",
       "4125 2007-10-16   6030.09  6056.95  6124.04  6040.71  6092.06\n",
       "4126 2007-10-17   6092.06  6057.43  6088.89  5982.20  6036.28\n",
       "4124 2007-10-15   5903.26  5934.77  6039.04  5866.13  6030.09\n",
       "4136 2007-10-31   5897.19  5984.71  6002.12  5871.48  5954.77\n",
       "4137 2007-11-01   5954.77  5978.94  6005.13  5912.50  5914.28\n",
       "...         ...       ...      ...      ...      ...      ...\n",
       "103  1991-05-17    105.77   105.12   106.75   104.96   106.75\n",
       "101  1991-05-15    107.19   106.56   106.60   106.42   106.57\n",
       "102  1991-05-16    106.57   105.83   105.86   105.69   105.77\n",
       "1    1990-12-20     99.98   104.30   104.39    99.98   104.39\n",
       "0    1990-12-19              96.05    99.98    95.79    99.98\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = data.sort_values(by = 'Close',ascending = False)\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "设置索引index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2007-10-16</th>\n",
       "      <td>6030.09</td>\n",
       "      <td>6056.95</td>\n",
       "      <td>6124.04</td>\n",
       "      <td>6040.71</td>\n",
       "      <td>6092.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-10-17</th>\n",
       "      <td>6092.06</td>\n",
       "      <td>6057.43</td>\n",
       "      <td>6088.89</td>\n",
       "      <td>5982.20</td>\n",
       "      <td>6036.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-10-15</th>\n",
       "      <td>5903.26</td>\n",
       "      <td>5934.77</td>\n",
       "      <td>6039.04</td>\n",
       "      <td>5866.13</td>\n",
       "      <td>6030.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-10-31</th>\n",
       "      <td>5897.19</td>\n",
       "      <td>5984.71</td>\n",
       "      <td>6002.12</td>\n",
       "      <td>5871.48</td>\n",
       "      <td>5954.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-11-01</th>\n",
       "      <td>5954.77</td>\n",
       "      <td>5978.94</td>\n",
       "      <td>6005.13</td>\n",
       "      <td>5912.50</td>\n",
       "      <td>5914.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-17</th>\n",
       "      <td>105.77</td>\n",
       "      <td>105.12</td>\n",
       "      <td>106.75</td>\n",
       "      <td>104.96</td>\n",
       "      <td>106.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-15</th>\n",
       "      <td>107.19</td>\n",
       "      <td>106.56</td>\n",
       "      <td>106.60</td>\n",
       "      <td>106.42</td>\n",
       "      <td>106.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-16</th>\n",
       "      <td>106.57</td>\n",
       "      <td>105.83</td>\n",
       "      <td>105.86</td>\n",
       "      <td>105.69</td>\n",
       "      <td>105.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-20</th>\n",
       "      <td>99.98</td>\n",
       "      <td>104.30</td>\n",
       "      <td>104.39</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-19</th>\n",
       "      <td></td>\n",
       "      <td>96.05</td>\n",
       "      <td>99.98</td>\n",
       "      <td>95.79</td>\n",
       "      <td>99.98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Preclose     Open  Highest   Lowest    Close\n",
       "Day                                                     \n",
       "2007-10-16   6030.09  6056.95  6124.04  6040.71  6092.06\n",
       "2007-10-17   6092.06  6057.43  6088.89  5982.20  6036.28\n",
       "2007-10-15   5903.26  5934.77  6039.04  5866.13  6030.09\n",
       "2007-10-31   5897.19  5984.71  6002.12  5871.48  5954.77\n",
       "2007-11-01   5954.77  5978.94  6005.13  5912.50  5914.28\n",
       "...              ...      ...      ...      ...      ...\n",
       "1991-05-17    105.77   105.12   106.75   104.96   106.75\n",
       "1991-05-15    107.19   106.56   106.60   106.42   106.57\n",
       "1991-05-16    106.57   105.83   105.86   105.69   105.77\n",
       "1990-12-20     99.98   104.30   104.39    99.98   104.39\n",
       "1990-12-19              96.05    99.98    95.79    99.98\n",
       "\n",
       "[8473 rows x 5 columns]"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = data.set_index('Day',drop = True)\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "日回报率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         Close  Daily_Return\n",
      "0       99.980           NaN\n",
      "1      104.390      0.044109\n",
      "2      109.130      0.045407\n",
      "3      114.550      0.049666\n",
      "4      120.250      0.049760\n",
      "...        ...           ...\n",
      "8468  3883.562      0.015109\n",
      "8469  3868.382     -0.003909\n",
      "8470  3800.350     -0.017587\n",
      "8471  3843.597      0.011380\n",
      "8472  3857.927      0.003728\n",
      "\n",
      "[8473 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('D:/Python2025/000001.csv') \n",
    "df['Daily_Return'] = (df['Close'] - df['Close'].shift(1)) / df['Close'].shift(1).fillna(1)\n",
    "print(df[['Close', 'Daily_Return']])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "累计回报率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         Close  Cumulative_Return\n",
      "0       99.980                NaN\n",
      "1      104.390           0.044109\n",
      "2      109.130           0.091518\n",
      "3      114.550           0.145729\n",
      "4      120.250           0.202741\n",
      "...        ...                ...\n",
      "8468  3883.562          37.843389\n",
      "8469  3868.382          37.691558\n",
      "8470  3800.350          37.011102\n",
      "8471  3843.597          37.443659\n",
      "8472  3857.927          37.586987\n",
      "\n",
      "[8473 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "df['Cumulative_Return'] = (1 + df['Daily_Return']).cumprod() - 1\n",
    "print(df[['Close',  'Cumulative_Return']])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
